import "./public-path";

import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

Vue.config.productionTip = false;

let instance = null;

function render(props) {
  const { container } = props;

  instance = new Vue({
    data: {
      store: props.store,
      globalInfo: {}
    },
    router,
    store,
    render: h => h(App)
    // ? 低版本浏览器，相同id查询为null
  }).$mount(container ? container.querySelector("#app2") : "#app2");
}

if (!window.__POWERED_BY_QIANKUN__) {
  render({});
}

export async function bootstrap() {
  console.log("[vue] vue child bootstrap");
}
export async function mount(props) {
  console.log("[vue] props from main framework", props);

  render(props);

  props.onGlobalStateChange((state, prev) => {
    // state: 变更后的状态; prev 变更前的状态
    console.log(state, prev);
    instance.globalInfo = state;
  });
  props.setGlobalState({ headImg: "。。爱上" });
}
export async function unmount() {
  instance.$destroy();
  instance = null;
}
